<template>
  <DataList ref="datalist" :cate="cate" :cols="cols" :name="name" skipExcelNumber="4" :excelHeader="excelHeader" :groupCheck = "groupCheck" 
 />
</template>
<script>
import DataList from "@/components/DataList";
import { getUser } from "@/utils/auth";
import { bulkAddZs, addZs, deleteZs, updateZs, getZs } from "@/api/招生.js";
import {findComponent} from "@/utils/ui";
import {get开设专业} from  "@/api/开设专业"
import linq from "linq"
import { debug } from 'util';
export default {
  components: {
    DataList
  },
  data() {
    return {
      cate: "A7-6-1招生表",
      name: "7.6.1 招生",
      excelHeader:{B3:"专业所属系部代码",C3:"专业所属系部名称",D3:"专业代码",E3:"专业名称（全称）",F3:"专业方向代码",G3:"专业方向名称（全称）",
      H3:"计划招生数（人）",I3:"实际录取情况",I4:"录取数（人）",J4:"录取率（%）",K3:"实际报到情况",K4:"报到数（人）",L4:"报到率（％）",M3:"区域生源报到情况",
      M4:"本地市",M5:"报到数（人）",N5:"比例（%）",O4:"本省市",O5:"报到数（人）",P5:"比例（%）",Q4:"本区域",Q5:"报到数（人）",R5:"比例（%）",S3:"报考本校原因",
      S4:"学校品牌",S5:"报考数（人）",T5:"比例（％）",U4:"专业爱好",U5:"报考数（人）",V5:"比例（％）",W4:"就业优势",W5:"报考数（人）",X5:"比例（％）",Y4:"技能培养",Y5:"报考数（人）",Z5:"比例（％）",
      AA4:"地理位置",AA5:"报考数（人）",AB5:"比例（％）",AC4:"他人推荐",AC5:"报考数（人）",AD5:"比例（％）",AE4:"其他",AE5:"报考数（人）",AF5:"比例（％）"},
      cols: [
        { label: "专业所属系部代码", prop: "BMBH" },
        { label: "专业所属系部名称", prop: "BMMC" },
        { label: "专业代码", prop: "ZYDM" },
        { label: "专业名称(全称)", prop: "ZYMC" },
        { label: "专业方向代码", prop: "ZYFXDM" },
        { label: "专业方向名称(全称)", prop: "ZYFXMC" },
        { label: "计划招生数(人)", prop: "DNJHZSS" },
        {label: "实际录取情况",data:[
          {label:"录取数(人)",prop:"SZLQS"},
          {label:"录取率(%)",prop:"SZLQL"}
        ]},
        {label: "实际报到情况",data:[
          {label:"报到数(人)",prop:"BDQK_BDS"},
          {label:"报到率(%)",prop:"BDQK_BDL"}
        ]},
        { label: "区域生源报到情况" ,data:[
              {label:"本地市",data:[
                {label:"报到数(人)",prop:"BDQK_BDS_BDS"},
                {label:"比例(%)",prop:"BDQK_BDS_BL"}
                ]},
                {label:"本省市",data:[
                {label:"报到数(人)",prop:"BDQK_BSS_BDS"},
                {label:"比例(%)",prop:"BDQK_BSS_BL"}
                ]},
                {label:"本区域",data:[
                {label:"报到数(人)",prop:"BDQK_BQY_BDS"},
                {label:"比例(%)",prop:"BDQK_BQY_BL"}
                ]}
        ]}
        ,
        { label: "报考本校原因" ,data:[
              {label:"学校品牌",data:[
                {label:"报考数(人)",prop:"BKYY_XXPP_RS"},
                {label:"比例(%)",prop:"BKYY_XXPP_BL"}
                ]},
                {label:"专业爱好",data:[
                {label:"报考数(人)",prop:"BKYY_ZYAH_RS"},
                {label:"比例(%)",prop:"BKYY_ZYAH_BL"}
                ]},
                {label:"就业优势",data:[
                {label:"报考数(人)",prop:"BKYY_JYYS_RS"},
                {label:"比例(%)",prop:"BKYY_JYYS_BL"}
                ]},
                {label:"技能培养",data:[
                {label:"报考数(人)",prop:"BKYY_JNPY_RS"},
                {label:"比例(%)",prop:"BKYY_JNPY_BL"}
                ]},
                {label:"地理位置",data:[
                {label:"报考数(人)",prop:"BKYY_DLWZ_RS"},
                {label:"比例(%)",prop:"BKYY_DLWZ_BL"}
                ]},
                {label:"他人推荐",data:[
                {label:"报考数(人)",prop:"BKYY_TRTJ_RS"},
                {label:"比例(%)",prop:"BKYY_TRTJ_BL"}
                ]}
                ,
                {label:"其他",data:[
                {label:"报考数(人)",prop:"BKYY_QT_RS"},
                {label:"比例(%)",prop:"BKYY_QT_BL"}
                ]}
        ]}
      ]
    };
  },
  methods: {
    getSummaries(list){
      //
        const sums = [];
         this.cols.forEach((column, index) => {
            sums[index]="";
        });
         sums[0]="合计";
         sums[6]="系部数:"+linq.from(list).distinct("$.BMBH").count()
         sums[8]="专业数:"+linq.from(list).distinct("$.ZYDM").count()
         sums[10]="方向数:"+linq.from(list).distinct("$.ZYFXDM").count()
         sums[12]="总人数:"+linq.from(list).sum("$.DNJHZSS")
         sums[13]=""+linq.from(list).sum("$.SZLQS")
         sums[14]=""+((linq.from(list).sum("$.SZLQS")/linq.from(list).sum("$.DNJHZSS"))*100).toFixed(2)
         sums[15]=""+linq.from(list).sum("$.BDQK_BDS")
         sums[16]=""+((linq.from(list).sum("$.BDQK_BDS")/linq.from(list).sum("$.DNJHZSS"))*100).toFixed(2)
         sums[17]=""+linq.from(list).sum("$.BDQK_BDS_BDS")
         sums[18]=""+((linq.from(list).sum("$.BDQK_BDS_BDS")/linq.from(list).sum("$.DNJHZSS"))*100).toFixed(2)
         sums[19]=""+linq.from(list).sum("$.BDQK_BSS_BDS")
         sums[20]=""+((linq.from(list).sum("$.BDQK_BSS_BDS")/linq.from(list).sum("$.DNJHZSS"))*100).toFixed(2)
         sums[21]=""+linq.from(list).sum("$.BDQK_BQY_BDS")
         sums[22]=""+((linq.from(list).sum("$.BDQK_BQY_BDS")/linq.from(list).sum("$.DNJHZSS"))*100).toFixed(2)
         sums[23]=""+linq.from(list).sum("$.BKYY_XXPP_RS")
         sums[24]=""+((linq.from(list).sum("$.BKYY_XXPP_RS")/linq.from(list).sum("$.DNJHZSS"))*100).toFixed(2)
         sums[25]=""+linq.from(list).sum("$.BKYY_ZYAH_RS")
         sums[26]=""+((linq.from(list).sum("$.BKYY_ZYAH_RS")/linq.from(list).sum("$.DNJHZSS"))*100).toFixed(2)
         sums[27]=""+linq.from(list).sum("$.BKYY_JYYS_RS")
         sums[28]=""+((linq.from(list).sum("$.BKYY_JYYS_RS")/linq.from(list).sum("$.DNJHZSS"))*100).toFixed(2)
         sums[29]=""+linq.from(list).sum("$.BKYY_JNPY_RS")
         sums[30]=""+((linq.from(list).sum("$.BKYY_JNPY_RS")/linq.from(list).sum("$.DNJHZSS"))*100).toFixed(2)
         sums[31]=""+linq.from(list).sum("$.BKYY_DLWZ_RS")
         sums[32]=""+((linq.from(list).sum("$.BKYY_DLWZ_RS")/linq.from(list).sum("$.DNJHZSS"))*100).toFixed(2)
         sums[33]=""+linq.from(list).sum("$.BKYY_TRTJ_RS")
         sums[34]=""+((linq.from(list).sum("$.BKYY_TRTJ_RS")/linq.from(list).sum("$.DNJHZSS"))*100).toFixed(2)
         sums[35]=""+linq.from(list).sum("$.BKYY_QT_RS")
         sums[36]=""+((linq.from(list).sum("$.BKYY_QT_RS")/linq.from(list).sum("$.DNJHZSS"))*100).toFixed(2)
         sums[37]= "通过:"+linq.from(list).where("$.审核状态=='通过'").count();
         sums[37]+= ",不通过:"+linq.from(list).where("$.审核状态=='不通过'").count();
         sums[37] += ",待审核:"+linq.from(list).where("$.审核状态=='待审核'").count();
 
       return sums;
      //
    },
    async  onDlgCreated(model) {
            var dd = findComponent(this,"ZYFXMC");
          var ZYFXMC = linq.from( this.$root.开设专业).distinct("$.ZYFXMC").toArray();
        
          dd.$attrs.items = ZYFXMC.map(item => {
            return { label: item.ZYFXMC, value: item.ZYFXMC};
          });
    },
 check(array,list) {
     return new Promise(async (resolve,reject)=>{
         try{
          var user = getUser();
          var 专业 = await get开设专业(user.XXID,user.CJPC)
             
          //是否已经存在相同
          
          var err =  linq.from(array).select("$.ZYDM+','+$.ZYFXDM").except(linq.from(专业).select("$.ZYDM+','+$.ZYFXDM").toArray()).toArray();
          linq.from(array).where(e=>err.indexOf(e.ZYDM+','+e.ZYFXDM) !==-1).forEach(e=>e.error=e.error?e.error+";":''+"开设专业表不存在对应的专业代码与专业方向代码组合合");
          //把错误的教师姓名替代掉
          err =  linq.from(array).select("$.ZYDM+','+$.ZYMC+','+$.ZYFXDM+','+$.ZYFXMC").except(linq.from(专业).select("$.ZYDM+','+$.ZYMC+','+$.ZYFXDM+','+$.ZYFXMC").toArray()).toArray();
          linq.from(array).where(e=>err.indexOf(e.ZYDM+','+e.ZYMC+','+e.ZYFXDM+','+e.ZYFXMC) !==-1).
          forEach(e=>{
            var d = linq.from(专业).firstOrDefault(item=>item.ZYDM == e.ZYDM && item.ZYFXDM == e.ZYFXDM);
            if(d){
              e.ZYMC = d.ZYMC;
              e.ZYFXMC = d.ZYFXMC;
              e.BMMC = d.BMMC;
              e.BMBH = d.BMBH;
            }
          });
            resolve();
          }catch(e){
            reject(e);
          }
     }) 
    },
    async  bulkAdd(array){
       await  bulkAddZs({Zs:array});
    },
    onChange(model, field, value) {
      //
     if (field == "ZYFXMC") {
        
        var temp =  linq.from( this.$root.开设专业).first(item=>item.ZYFXMC==value);
        model.BMBH = temp.BMBH;
        model.BMMC = temp.BMMC;
        model.ZYMC = temp.ZYMC;
        model.ZYDM = temp.ZYDM;
        
        model.ZYFXDM = temp.ZYFXDM;
        
      }
      //
      
      model.SZLQL=((Number(model.SZLQS)/Number(model.DNJHZSS))*100).toFixed(2)+'';
      model.SZLQL=isNaN(model.SZLQL)?0:model.SZLQL
      model.BDQK_BDL=((Number(model.BDQK_BDS)/Number(model.SZLQS))*100).toFixed(2)+'';
      model.BDQK_BDL=isNaN(model.BDQK_BDL)?0:model.BDQK_BDL
      model.BDQK_BDS_BL=((Number(model.BDQK_BDS_BDS)/Number(model.BDQK_BDS))*100).toFixed(2)+'';
      model.BDQK_BDS_BL=isNaN(model.BDQK_BDS_BL)?0:model.BDQK_BDS_BL
      model.BDQK_BSS_BL=((Number(model.BDQK_BSS_BDS)/Number(model.BDQK_BDS))*100).toFixed(2)+'';
      model.BDQK_BSS_BL=isNaN(model.BDQK_BSS_BL)?0:model.BDQK_BSS_BL
      model.BDQK_BQY_BL=((Number(model.BDQK_BQY_BDS)/Number(model.BDQK_BDS))*100).toFixed(2)+'';
model.BDQK_BQY_BL=isNaN(model.BDQK_BQY_BL)?0:model.BDQK_BQY_BL
      model.BKYY_XXPP_BL=((Number(model.BKYY_XXPP_RS)/Number(model.BDQK_BDS))*100).toFixed(2)+'';
      model.BKYY_XXPP_BL=isNaN(model.BKYY_XXPP_BL)?0:model.BKYY_XXPP_BL
      model.BKYY_ZYAH_BL=((Number(model.BKYY_ZYAH_RS)/Number(model.BDQK_BDS))*100).toFixed(2)+'';
      model.BKYY_ZYAH_BL=isNaN(model.BKYY_ZYAH_BL)?0:model.BKYY_ZYAH_BL
      model.BKYY_JYYS_BL=((Number(model.BKYY_JYYS_RS)/Number(model.BDQK_BDS))*100).toFixed(2)+'';
      model.BKYY_JYYS_BL=isNaN(model.BKYY_JYYS_BL)?0:model.BKYY_JYYS_BL
      
      model.BKYY_JNPY_BL=((Number(model.BKYY_JNPY_RS)/Number(model.BDQK_BDS))*100).toFixed(2)+'';
      model.BKYY_JNPY_BL=isNaN(model.BKYY_JNPY_BL)?0:model.BKYY_JNPY_BL
      model.BKYY_DLWZ_BL=((Number(model.BKYY_DLWZ_RS)/Number(model.BDQK_BDS))*100).toFixed(2)+'';
      model.BKYY_DLWZ_BL=isNaN(model.BKYY_DLWZ_BL)?0:model.BKYY_DLWZ_BL
      model.BKYY_TRTJ_BL=((Number(model.BKYY_TRTJ_RS)/Number(model.BDQK_BDS))*100).toFixed(2)+'';
      model.BKYY_TRTJ_BL=isNaN(model.BKYY_TRTJ_BL)?0:model.BKYY_TRTJ_BL
      model.BKYY_QT_BL=((Number(model.BKYY_QT_RS)/Number(model.BDQK_BDS))*100).toFixed(2)+'';
      model.BKYY_QT_BL=isNaN(model.BKYY_QT_BL)?0:model.BKYY_QT_BL
    },
  calField(list){
      list.forEach(model=>{
         model.SZLQL=((Number(model.SZLQS)/Number(model.DNJHZSS))*100).toFixed(2)+'';
      model.BDQK_BDL=((Number(model.BDQK_BDS)/Number(model.SZLQS))*100).toFixed(2)+'';
      model.BDQK_BDS_BL=((Number(model.BDQK_BDS_BDS)/Number(model.BDQK_BDS))*100).toFixed(2)+'';
      model.BDQK_BSS_BL=((Number(model.BDQK_BSS_BDS)/Number(model.BDQK_BDS))*100).toFixed(2)+'';
      model.BDQK_BQY_BL=((Number(model.BDQK_BQY_BDS)/Number(model.BDQK_BDS))*100).toFixed(2)+'';

      model.BKYY_XXPP_BL=((Number(model.BKYY_XXPP_RS)/Number(model.BDQK_BDS))*100).toFixed(2)+'';
      model.BKYY_ZYAH_BL=((Number(model.BKYY_ZYAH_RS)/Number(model.BDQK_BDS))*100).toFixed(2)+'';
      model.BKYY_JYYS_BL=((Number(model.BKYY_JYYS_RS)/Number(model.BDQK_BDS))*100).toFixed(2)+'';
      
      model.BKYY_JNPY_BL=((Number(model.BKYY_JNPY_RS)/Number(model.BDQK_BDS))*100).toFixed(2)+'';
      model.BKYY_DLWZ_BL=((Number(model.BKYY_DLWZ_RS)/Number(model.BDQK_BDS))*100).toFixed(2)+'';
      model.BKYY_TRTJ_BL=((Number(model.BKYY_TRTJ_RS)/Number(model.BDQK_BDS))*100).toFixed(2)+'';
      model.BKYY_QT_BL=((Number(model.BKYY_QT_RS)/Number(model.BDQK_BDS))*100).toFixed(2)+'';
      //

           model.SZLQL=isNaN(model.SZLQL)?0:model.SZLQL;
        model.BDQK_BDL=isNaN(model.BDQK_BDL)?0:model.BDQK_BDL;
           model.BDQK_BDS_BL=isNaN(model.BDQK_BDS_BL)?0:model.BDQK_BDS_BL;
            model.BDQK_BSS_BL=isNaN(model.BDQK_BSS_BL)?0:model.BDQK_BSS_BL;
      
     
         model.BDQK_BQY_BL=isNaN(model.BDQK_BQY_BL)?0:model.BDQK_BQY_BL;
        model.BKYY_XXPP_BL=isNaN(model.BKYY_XXPP_BL)?0:model.BKYY_XXPP_BL;
         model.BKYY_ZYAH_BL=isNaN(model.BKYY_ZYAH_BL)?0:model.BKYY_ZYAH_BL;
        model.BKYY_JYYS_BL=isNaN(model.BKYY_JYYS_BL)?0:model.BKYY_JYYS_BL;
         model.BKYY_JNPY_BL=isNaN(model.BKYY_JNPY_BL)?0:model.BKYY_JNPY_BL;
        model.BKYY_DLWZ_BL=isNaN(model.BKYY_DLWZ_BL)?0:model.BKYY_DLWZ_BL;
         model.BKYY_TRTJ_BL=isNaN(model.BKYY_TRTJ_BL)?0:model.BKYY_TRTJ_BL;
        model.BKYY_QT_BL=isNaN(model.BKYY_QT_BL)?0:model.BKYY_QT_BL;
      //
      })
     },
    async fetchData() {
      var user =  getUser()
      var datas = await getZs(user.XXID,user.CJPC);
      return datas;
    },
    onadd(model) {
      //
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
           
      
          console.log(JSON.stringify(temp));
          var model = await addZs(temp);
          resolve(model);
      })
      
    },
    onupdate(model) {
      //
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
           
          console.log(JSON.stringify(temp));
          var model = await updateZs(temp);
          resolve(model);
      })
      //
    },
    ondelete(model) {
       var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
         await deleteZs(temp);
          resolve();
      })
    }
  }
};
</script>
<style>
</style>